"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index_module = require("./index.module.js");
const index = require("../node_modules/element-plus/es/components/button/index.js");
function getSlotView(set, key, slots, defaultFuc) {
  if (!set) {
    return null;
  }
  const { slotFuc, slotName } = set;
  if (slotFuc) {
    return slotFuc(key);
  } else if (slotName) {
    const slot = slots ? slots[slotName] : null;
    if (slot) {
      return slot(key);
    }
  }
  if (defaultFuc) {
    return defaultFuc();
  }
  return null;
}
const buttonClick = (itemSet, clickProp, defaultClick) => {
  const { context } = clickProp;
  const { emit } = context;
  if (itemSet.click) {
    const type = typeof itemSet.click;
    if (type === "string") {
      emit(itemSet.click, clickProp);
    } else if (type === "function") {
      itemSet.click(clickProp);
    }
  } else if (defaultClick) {
    defaultClick();
  }
};
function getElButtonItem(itemSet, clickProp, defaultText, defaultClick) {
  const label = itemSet.label || defaultText;
  const style2 = Object.assign({ marginLeft: "20px" }, itemSet.style);
  const iconStyle = Object.assign(label ? { marginRight: "5px" } : {}, itemSet.iconStyle);
  let show = true;
  if (itemSet.showFuc) {
    show = itemSet.showFuc(clickProp);
  }
  if (show && !itemSet.hidden) {
    return /* @__PURE__ */ React.createElement(index.ElButton, {
      type: "primary",
      size: "small",
      ...itemSet.props,
      style: style2,
      onClick: () => {
        buttonClick(itemSet, clickProp, defaultClick);
      }
    }, itemSet.icon && /* @__PURE__ */ React.createElement("i", {
      className: itemSet.icon,
      style: iconStyle
    }), label && /* @__PURE__ */ React.createElement("span", {
      style: itemSet.labelStyle
    }, label));
  }
  return null;
}
function formatTableOption(tableSet, context, getClickProp) {
  const { slots = {} } = context;
  const prop = getClickProp();
  const option = [];
  if (tableSet.select) {
    const props = Object.assign({ fixed: "left", type: "selection" }, tableSet.select.props);
    option.push({
      props
    });
  }
  if (tableSet.button) {
    const { header, slot, list } = tableSet.button;
    const props = Object.assign({ fixed: "left" }, tableSet.button.props);
    let defaltSlot = null;
    if (slot) {
      defaltSlot = getSlotView(slot, prop, slots);
    } else if (list && list.length > 0) {
      defaltSlot = (row) => {
        return /* @__PURE__ */ React.createElement("div", {
          style: { display: "flex", flexDirection: "row", flexWrap: "wrap" }
        }, list.map((item) => {
          let show = true;
          if (item.showFuc) {
            show = item.showFuc(row.row);
          }
          if (show) {
            return /* @__PURE__ */ React.createElement("div", {
              className: index_module.default.optItem,
              style: item.style,
              onClick: () => {
                item.click(getClickProp(row.row));
              }
            }, item.icon && /* @__PURE__ */ React.createElement("i", {
              className: item.icon,
              style: item.iconStyle
            }), /* @__PURE__ */ React.createElement("span", {
              style: item.labelStyle
            }, item.label, " "));
          } else {
            return null;
          }
        }));
      };
    }
    const slotsItem = {
      header: getSlotView(header, prop, slots),
      default: defaltSlot
    };
    option.push({
      props,
      slots: slotsItem
    });
  }
  if (tableSet.list && tableSet.list.length > 0) {
    for (let i = 0; i < tableSet.list.length; i++) {
      const item = tableSet.list[i];
      if (item.hidden) {
        continue;
      }
      const { props, header, slot, name } = item;
      props.prop = props.prop || name;
      const slotsItem = {
        header: getSlotView(header, prop, slots),
        default: (row) => {
          return getSlotView(slot, getClickProp(row.row), slots);
        }
      };
      option.push({
        props,
        slots: slotsItem
      });
    }
  }
  return option;
}
exports.formatTableOption = formatTableOption;
exports.getElButtonItem = getElButtonItem;
exports.getSlotView = getSlotView;
